<html>
<head><meta charset="utf-8"><title>async drop · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html">async drop</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="204199028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204199028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204199028">(Jul 17 2020 at 12:22)</a>:</h4>
<p><span class="user-mention" data-user-id="256759">@boats</span> Feel free to redirect to the RFC thread, but I feel like I must be missing something obvious. Is there a reason we prefer to simultaneously poll all the fields instead of starting with one, waiting for it to return ready, then doing the next one?</p>
<p>My intuition says that it's "faster" to do what the RFC proposes, but I don't see discussion of this alternative in it.</p>



<a name="204199082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204199082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204199082">(Jul 17 2020 at 12:23)</a>:</h4>
<p>can't do the alternative statelessly</p>



<a name="204199460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204199460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204199460">(Jul 17 2020 at 12:27)</a>:</h4>
<p>Ah, right. I guess it would just add N states to the async context, but wouldn't be generally as easy (or possible?) in manual impls.</p>



<a name="204199589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204199589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204199589">(Jul 17 2020 at 12:28)</a>:</h4>
<p>the state cant be stored in the async context because we need to virtually dispatch poll_drop_ready for trait objects</p>



<a name="204199818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204199818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204199818">(Jul 17 2020 at 12:30)</a>:</h4>
<p>Hm, yes. This RFC would also expand all vtables by a word, right?</p>



<a name="204200214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204200214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204200214">(Jul 17 2020 at 12:35)</a>:</h4>
<p>And do we want a needs_async_drop for vec and others so we can avoid 2x as many calls to dtors pre-optimization (and  potentially post, for trait objects)? I guess we can zero the word in the vtable if the impl is a no-op to avoid call overhead or something like that.</p>



<a name="204200569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204200569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204200569">(Jul 17 2020 at 12:39)</a>:</h4>
<p>yea that would make sense</p>



<a name="204200943"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204200943" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204200943">(Jul 17 2020 at 12:42)</a>:</h4>
<p>Oh, actually, I guess it's not as big a cost as I was thinking since Vec and friends would only do this from <em>their</em> async drop methods, we'd not add anything to the "common case" of normal Drop being called, right?</p>



<a name="204201752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204201752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204201752">(Jul 17 2020 at 12:52)</a>:</h4>
<p>im not sure what you mean</p>



<a name="204201802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204201802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204201802">(Jul 17 2020 at 12:53)</a>:</h4>
<p>when you drop a vec under this RFC, it would first call poll_drop_ready on the vec until it returns ready, and then call drop on the vec</p>



<a name="204201825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204201825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204201825">(Jul 17 2020 at 12:53)</a>:</h4>
<p>maybe theres a way to combine these into a single function</p>



<a name="204202077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204202077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204202077">(Jul 17 2020 at 12:55)</a>:</h4>
<p>I mean that dropping in a non-async context doesn't change at all</p>



<a name="204202230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204202230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204202230">(Jul 17 2020 at 12:57)</a>:</h4>
<p>I don't think you gain anything from combining if it's in a "known type", though with a trait object you might -- something like drop_async that will internally know the type it is dropping (and so avoid dynamic dispatch) but I don't know that it's all that much of a win</p>



<a name="204202993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204202993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204202993">(Jul 17 2020 at 13:04)</a>:</h4>
<p>i think it would just mean 1 less virtual call by calling drop from inside drop_async</p>



<a name="204204066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204204066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204204066">(Jul 17 2020 at 13:15)</a>:</h4>
<p>true. Though -- in theory -- we could also look at replacing the existing drop in vtables with a <code>maybe_async_drop(is_async_context: bool) -&gt; Poll&lt;()&gt;</code></p>



<a name="204204079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204204079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204204079">(Jul 17 2020 at 13:15)</a>:</h4>
<p>to avoid growing vtables etc</p>



<a name="204204168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204204168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204204168">(Jul 17 2020 at 13:16)</a>:</h4>
<p>Are we expecting RawWakerVtable to optionally gain an async drop field?</p>



<a name="204214765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204214765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204214765">(Jul 17 2020 at 14:48)</a>:</h4>
<p>One question that I have about "async drop" is the interaction with <a href="https://docs.rs/async-task/3.0.0/async_task/struct.JoinHandle.html#method.cancel"><code>async_task::JoinHandle::cancel</code></a> -- currently cancellation is implemented as "stop polling the task on the executor". But would there be a way to ensure async drop is called on cancel?</p>



<a name="204215080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204215080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204215080">(Jul 17 2020 at 14:51)</a>:</h4>
<p>Hmm, perhaps what I'm wondering is if there's an async equivalent to <code>drop(my_type)</code> to force the async Drop destructor to run? I think we'd need something like that to ensure async drop is run on task cancellation?</p>



<a name="204215211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204215211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204215211">(Jul 17 2020 at 14:52)</a>:</h4>
<p><span class="user-mention" data-user-id="211722">@Yoshua Wuyts</span> I think the answer is yes and is in the RFC? You'd have <code>async fn async_drop(v: T) {  }</code> which would ensure the async drop glue runs for T</p>



<a name="204215296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204215296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204215296">(Jul 17 2020 at 14:53)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> ahh, yeah that would be this section right? <a href="https://github.com/withoutboats/rfcs/blob/poll-drop-ready/text/0000-poll-drop-ready.md#guarantees-about-when-poll_drop_ready-is-called">https://github.com/withoutboats/rfcs/blob/poll-drop-ready/text/0000-poll-drop-ready.md#guarantees-about-when-poll_drop_ready-is-called</a></p>



<a name="204215393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204215393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204215393">(Jul 17 2020 at 14:53)</a>:</h4>
<p>that too, but I meant the first code example in the guide section <a href="https://github.com/withoutboats/rfcs/blob/poll-drop-ready/text/0000-poll-drop-ready.md#guide-level-explanation">https://github.com/withoutboats/rfcs/blob/poll-drop-ready/text/0000-poll-drop-ready.md#guide-level-explanation</a></p>



<a name="204215549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/async%20drop/near/204215549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/async.20drop.html#204215549">(Jul 17 2020 at 14:55)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> ah I missed that -- that's perfect; thanks!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>